<template>
	<view>
		<Search @click="search"></Search>
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular="true">
			<swiper-item v-for="(item,index) in swiper" :key="item.goods_id" class="swiper-wrap">
				<navigator :url="`/subpkg/goods_detail/goods_detail?goods_id=${item.goods_id}`">
					<image :src="item.image_src" mode="widthFix"></image>
				</navigator>
			</swiper-item>
		</swiper>
		
		<view class="class-wrap">
			<view class="item-warp" v-for="(item,index) in classData" :key="index" @click="enterClass(item.name)">
				<image :src="item.image_src" mode=""></image>
			</view>
		</view>
		
		<view class="floor" v-for="(item,index) in floordata" :key="index">
			<view class="title">
				<image :src="item.floor_title.image_src" mode="widthFix"></image>
			</view>
			<view class="main" >
				<view class="main-left" @click="enterList(item.product_list[0].navigator_url)">
					<image 
					:src="item.product_list[0].image_src" 
					mode="widthFix" 
					:style="{width:item.product_list[0].image_width+'rpx'}"></image>
				</view>
				<view class="main-right" >
						<image
						 v-for="(obj,i) in item.product_list" :key="i"
						 @click="enterList(obj.navigator_url)"
						:src="obj.image_src" 
						mode="widthFix" v-if="i!==0"
						:style="{width:obj.image_width+'rpx'}"
						></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiper: [],
				classData: [],
				floordata: []
			};
		},
		onLoad() {
			this.getSwiperList()
			this.getClassData()
			this.getfloordata()
		},
		methods: {
			async getSwiperList() {
				const { data } = await uni.$http.get('/api/public/v1/home/swiperdata')
				this.swiper = data.message
			},
			async getClassData() {
				const { data } = await uni.$http.get('/api/public/v1/home/catitems')
				this.classData = data.message
			},
			async getfloordata() {
				const { data } = await uni.$http.get('/api/public/v1/home/floordata')
				this.floordata = data.message
			},
			enterClass(name) {
				if (name === '分类') {
					uni.switchTab({
						url: '/pages/class/class'
					})
				}
			},
			enterList(url,obj){
				const query=url.split('?')[1]
				uni.navigateTo({
					url:`/subpkg/goods_list/goods_list?${query}`
				})
			},
			search(){
				uni.navigateTo({
					url:"/subpkg/SearchShopping/SearchShopping"
				})
			}
		},
	}
</script>

<style lang="scss">
	.swiper-wrap image {
		width: 100%;
		height: 100%;
	}

	.class-wrap {
		display: flex;
		justify-content: space-around;
		margin: 10rpx 0;

		.item-warp image {
			width: 150rpx;
			height: 150rpx;
		}
	}
	.floor{
		margin: 10rpx 0;
		.main {
			display: flex;
			padding: 0 10rpx;
			.main-right{
				display: flex;
				justify-content: space-around;
				flex-wrap: wrap;
			}
		}
	}
	
</style>
